Component({
  properties: {
    text: {
      type: String,
      value: ""
    },
    visible: {
      type: Boolean,
      value: false
    }
  },
  data: {
    len: 6
  },
  methods: {
    handleClick(e) {
      let inputKey = e.currentTarget.dataset.item;
      let oldNumText = this.data.text;
      let newText = this.inputValue(inputKey);
      if (oldNumText !== newText) {
        this.triggerEvent('change', newText)
      }
    },
    inputValue(inputKey) {
      if (inputKey === 'del') {
        if (this.data.text) {
          return this.data.text.substring(0, this.data.text.length - 1)
        }
        return this.data.text;
      }

      if (inputKey === "clear") {
        return "";
      }
      if (this.data.text.length < this.data.len) {
        return this.data.text + inputKey;
      }
      return this.data.text;
    }
  }
});
